package com.v5.mr.avgvalue;

import java.io.IOException;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class AvgValueReducer extends Reducer<Text, LongWritable, Text, DoubleWritable> {

	@Override
	protected void reduce(Text k3, Iterable<LongWritable> v3,Context context) throws IOException, InterruptedException {
		// 求v3的平均值
		long total = 0;
		long count = 0;
		
		for(LongWritable l:v3){
			total = total + l.get();
			count ++;
		}
		
		//输出
		context.write(new Text("The avg value is : "), new DoubleWritable(total/count));
	}

}
